package com.itheima.mapper;

import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @Select("select * from t_user where username = #{username}")
    User findByUsername(String username);

    /**
     * 根据用户id查询用户拥有的角色
     * @param userId
     * @return
     */
    @Select("select r.* from t_role r,t_user_role ur where r.id = ur.role_id and ur.user_id = #{userId}")
    List<Role> findRolesByUserId(Integer userId);
}
